define(function (require, exports, module) {
	var Grid = require("grid");
	var aw = require("ajaxwrapper");
	var Dialog = require("dialog");
	var gridEvents = require("../handler/gridEvents");
	
    var instance = {
        initComponent: function (params,widget) {
        	var component = new Grid({
                parentNode: ".J-grid", 
                autoRender:false,
                model : {
                    url : "api/travelcontractcharge/query",
                    params: function() {
                    	var subnav=widget.get("subnav");
                        return {
                        	"travelContract.signUpDate":subnav.getValue("dateRange").start,
     						"travelContract.signUpDateEnd":subnav.getValue("dateRange").end,
     						"travelContract.status":subnav.getValue("status"),
     						"travelContract.servicePoint":subnav.getValue("servicePoint"),
     						fetchProperties: "*,travelContract.*,travelContract.member.personalInfo.*," +
     								"travelContract.member.personalInfo.contactAddresses.*," +
     								"travelContract.member.personalInfo.address," +
     								"travelContract.member.personalInfo.houseRegister.*," +
     								"travelContract.member.personalInfo.areaAddress.*," +
     								"travelContract.member.personalInfo.contactAddresses.detailAddress," +
     								"travelContract.member.personalInfo.contactAddresses.address.*," +
     								"travelContract.member.personalInfo.contactAddresses.communityData.*," +
     								"travelContract.member.personalInfo.address.*,travelContract.productRule.*," +
     								"travelContract.productRule.product.*,travelContract.productType.*," +
     								"travelContract.productBatch.*,travelContract.status.*,travelContract.unit.*" 
                        };
                    },
                    columns : [{
        				name:"travelContract.contactNo",
        				label:"合同号"
        			},{
        				name:"travelContract.memberCertificates",
        				label:"会员证号"        				
					},{
						name:"travelContract.member.personalInfo.name",
						label:"会员"
					},{						
						name:"travelContract.productRule.product.name",
        				label:"产品",
					},{
        				name:"travelContract.productType.name",
        				label:"产品类型",
        			},{
						name:"travelContract.number",
						label:"购买份数"
					},{
        				name:"travelContract.price",
        				label:"金额（元）",
        				format: function(value, rowData) {
			                return value.toFixed(2);
			            }
					},{
						name:"travelContract.signUpDate",
						label:"签约日期",
						format:"date"
					},{
        				name:"travelContract.status.value",
        				label:"签约状态",
        			},{
						name:"status.value",
						label:"收费状态"
					},{
						name:"operate",
						label:"操作",
						format:"button",
						formatparams:[{
							id:"edit",
							icon:"icon-edit",
							show:function(value,data){
								if (data.travelContract.status.key == "Initial") {
									return true;
			                    } else {
			                        return false;
			                    }
							},
							handler:function(index,data,rowEle){
								gridEvents.show(widget,data,false);
							}
						},{
							key:"delete",
							icon:"icon-remove",
							show:function(value,data){
								if (data.travelContract.status.key == "Initial") {
									return true;
			                    } else {
			                        return false;
			                    }
							},
							handler:function(index,data,rowEle){
								Dialog.confirm({
  									content : "是否确认删除该条数据？",
  									confirm : function(){										
										aw.saveOrUpdate("api/travelcontract/"+data.travelContract.pkTravelContract+"/deleteall",data,function(data){
  											widget.get("grid").refresh();
  										});
  									},
  									cancel : function(){
  										Dialog.close;
  									}
  								});
							}	
						},{
							id:"show",
							text: "查看",
							handler:function(index,data,rowEle){
								gridEvents.show(widget,data,true);
							}
						}]
					}]
                }
            });
            widget.set("grid",component);
        }
    };
    module.exports = instance;
});